# We cannot do this:
# list(list(c("a","b")), c("d"))
# to get
# list(c("a", "b"), c("d"))

list_combine <- function(list1 = list(), list2 = list()){
  length1 <- length(list1)
  length2 <- length(list2)
  
  if(length2 == 0){
    if(length1 == 0){
      return(NULL)
    }else{
      return(list1)
    }
  }
  
  if(length2 == 1){
    if(length1 == 0){
      return(list2)
    }else{
      if(length1 == 1){
        return(list(list1[[1]], list2[[1]]))
      }
    }
  }
  
  order_str <- "out_list  <- list("
  for(i in 1:length1){
    order_str <- paste(order_str, "list1[[",i,"]]", sep = "")
    if(i != length1){
      order_str <- paste(order_str, ", ", sep = "")
    }
  }
  order_str <- paste(order_str, ", ", sep = "")
  for(i in 1:length2){
    order_str <- paste(order_str, "list2[[",i,"]]", sep = "")
    if(i != length2){
      order_str <- paste(order_str, ", ", sep = "")
    }
  }
  order_str <- paste(order_str, ")", sep = "")
  # cat(order_str)
  eval(parse(text = order_str))
  return(out_list)
}


# list1 <- list(c("a", "b"), "haha", data.frame(c(1,2,3), c("la","do","ti")))
# list2 <- list("haha2", factor(1:20))
# 
# list1 <- list(c("a", "b"))
# list2 <- list("haha2", factor(1:20))
# 
# list1 <- list(c("a", "b"))
# list2 <- list("haha2")
# 
# list1 <- list(c("a", "b"), "haha", data.frame(c(1,2,3), c("la","do","ti")))
# list2 <- list("haha2")
# 
# list_combine(list1, list2)
